// vue.config.js
const TerserPlugin = require('terser-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const productionGzipExtensions = /\.(js|css|json|txt|html|ico|svg)(\?.*)?$/i;

module.exports = {
    productionSourceMap: true,
    configureWebpack: config=>{
        const plugins = [];
        // plugins.push(
        //     new UglifyJsPlugin({
        //         uglifyOptions: {
        //             warnings: false,
        //             compress: {
        //                 //
        //                 drop_console: true,
        //                 drop_debugger: false,
        //                 pure_funcs: ["console.log"] //移除console
        //             }
        //         },
        //         sourceMap: false,
        //         parallel: true
        //     })
        // );
        plugins.push(
            new CompressionWebpackPlugin({
                filename: "[path].gz[query]",
                algorithm: "gzip",
                test: productionGzipExtensions,
                threshold: 10240,
                minRatio: 0.8
            })
        );

        config.plugins = [...config.plugins, ...plugins];
    }
}
